﻿@{
    Layout = "../Shared/_Default.cshtml";
    var t_forum = (Model.Forum.Translations as IEnumerable<dynamic>)
        .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
            JDM.Int32(Svc.Localization.Language.EntityID));
    ViewBag.PageTitle = T(Res.Name("Title"), t_forum != null 
        ? JDM.String(t_forum.Name) 
        : JDM.String(Model.Forum.EntityID));
    ViewBag.PageHistory = String.IsNullOrWhiteSpace(Request.QueryParam("searchTerm")) 
        && String.IsNullOrWhiteSpace(Request.QueryParam("page"));
}

@section Breadcrumb
{
    @{
        Html.RenderAction(Loc.Act("_Breadcrumb").Set(new
        {
            id = JDM.Int32(Model.Forum.EntityID),
            full = false
        }).Localized());
    }
}
@section Toolbar
{
    <span>
        @T(Res.Name("Stat"), 
        JDM.Int32(Model.Forum.TopicCount), 
        JDM.Int32(Model.Forum.PostCount))
    </span>
    @if(Model.UserCanWrite)
    {
        <span class="separator">&nbsp;</span>
        <a href="@Url.Action(Loc.Act("Create").Ctrl("ForumTopic").Area("Wizard").Set(new
        {
            forumID = JDM.Int32(Model.Forum.EntityID)
        }).Localized())">@T(Res.Name("Topic"))</a>
    }
}
<div class="box">
    <section>
    @{
        Html.RenderPartial("_Description", (object)Model.Forum);
        if(!Model.UserCanWrite)
        {
            <div class="hint">
                <p>@T(Res.Name("ReadOnly"))</p>
            </div>
        }
    }
    </section>
    <section>
    @{
        if((Model.Forums.Items as IEnumerable<dynamic>).Any())
        {
            Html.RenderPartial("_Table", (object)Model.Forums);
        }
    }
    </section>
<div class="box">
    <header>
        <h3>@T(Res.Name("Announcments"))</h3>
    </header>
    <section>
    @{
        Html.RenderAction(Loc.Act("_Announcments").Set(new
        {
            forumID = JDM.Int32(Model.Forum.EntityID)
        }));
    }
    </section>
</div>
<div class="box">
    <header>
        <h3>@T(Res.Name("Topics"))</h3>
    </header>
    <section>
    @{
        Html.RenderPartial("_Topics", (object)Model.Topics);
        Html.RenderPartial("_Pager", new ViewDataDictionary
        {
            {"PageNum", 6},
            {"PageCount", Math.Ceiling(JDM.Double(Model.Topics.TotalCount) / Model.CountPerPage)},
            {"PageIndex", Request.QueryParam("page", 0)},
            {"PageParam", "page"},
            {"PageSize", Model.CountPerPage},
            {"PageRoute", Loc.Act("Show").Use("id", "searchTerm").Localized()}
        });
    }
    </section>
    <section>
    @{
        Html.RenderPartial("_Search", (object)Model.Forum);
    }
    </section>
</div>
